package com.zkingsoft.pojo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.zkingsoft.model.Function;
import com.zkingsoft.model.RolePwoer;

/**
 * @description 用户权限表示类
 * @author 姜友瑶
 * @data 2016-06-26
 */
public class UserPwoer {

	/**
	 * 表示顶层功能和他所对应的子功能
	 */
	private List<Function> functions;

	/**
	 * 所有用户功能权限映射 id: rolePwoer;
	 */
	private Map<Long, RolePwoer> powers;

	private Map<String, RolePwoer> pathPowers;

	public Map<String, RolePwoer> getPathPowers() {
		return pathPowers;
	}

	public void setPathPowers(Map<String, RolePwoer> pathPowers) {
		this.pathPowers = pathPowers;
	}

	public List<Function> getFunctions() {
		return functions;
	}

	public void setFunctions(List<Function> functions) {
		this.functions = functions;
	}

	public Map<Long, RolePwoer> getPowers() {
		return powers;
	}

	public void setPowers(Map<Long, RolePwoer> powers) {
		// 设置id映射和path映射
		pathPowers = new HashMap<>();
		Set<Long> idSet = powers.keySet();
		if (idSet != null) {
			for (Long id : idSet) {
				Function function= powers.get(id).getFunction();
				if(function!=null){
					String path = function.getFunctionPath();
					if (path != null) {
						pathPowers.put(path, powers.get(id));
					}
				}
			}
		}
		this.powers = powers;
	}

}
